// pages/xiuword/xiuword.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    defaultType: true,
    defaultType_a: true,
    defaultType_b: true,
    EMPLOYEE_NAME: '',//账号
    EMPLOYEE_PASSWORD_OLD: '',//旧密码
    EMPLOYEE_PASSWORD_NEW: '',//新密码
    EMPLOYEE_PASSWORD_REPEAT: '',//确定新密码
    EMPLOYEE_PASSWORD_OLD_a: true,//旧密码
    EMPLOYEE_PASSWORD_NEW_b: true,//新密码
    EMPLOYEE_PASSWORD_REPEAT_c: true,//确定新密码
  },


  eyeStatus: function () {
    this.data.defaultType = !this.data.defaultType
    this.data.EMPLOYEE_PASSWORD_OLD_a = !this.data.EMPLOYEE_PASSWORD_OLD_a

    this.setData({
      defaultType: this.data.defaultType,
      EMPLOYEE_PASSWORD_OLD_a: this.data.EMPLOYEE_PASSWORD_OLD_a,
    })
  },
  eyeStatus_a: function () {
    this.data.defaultType_a = !this.data.defaultType_a
    this.data.EMPLOYEE_PASSWORD_NEW_b = !this.data.EMPLOYEE_PASSWORD_NEW_b
    this.setData({
      defaultType_a: this.data.defaultType,
      EMPLOYEE_PASSWORD_NEW_b: this.data.EMPLOYEE_PASSWORD_NEW_b,
    })
  },

  eyeStatus_b: function () {
    this.data.defaultType_b = !this.data.defaultType_b
    this.data.EMPLOYEE_PASSWORD_REPEAT_c = !this.data.EMPLOYEE_PASSWORD_REPEAT_c
    this.setData({
      defaultType_b: this.data.defaultType_b,
      EMPLOYEE_PASSWORD_REPEAT_c: this.data.EMPLOYEE_PASSWORD_REPEAT_c
    })
  },

  //点击确定提交修改
  psword() {
    console.log(111);
    if (!this.data.EMPLOYEE_PASSWORD_NEW || !this.data.EMPLOYEE_PASSWORD_REPEAT || !this.data.EMPLOYEE_NAME || !this.data.EMPLOYEE_PASSWORD_OLD) {
      wx.showModal({
        title: '温馨提示',
        content: '请完善信息',
        success: function (res) {
          if (res.confirm) {//这里是点击了确定以后
            console.log('用户点击确定')
          } else {//这里是点击了取消以后
            console.log('用户点击取消')
          }
        }
      })
    } else if (this.data.EMPLOYEE_PASSWORD_NEW != this.data.EMPLOYEE_PASSWORD_REPEAT) {
      wx.showModal({
        title: '温馨提示',
        content: '两次密码输入不一致',
        success: function (res) {
          if (res.confirm) {//这里是点击了确定以后
            console.log('用户点击确定')
          } else {//这里是点击了取消以后
            console.log('用户点击取消')
          }
        }
      })
    } else {
      wx.request({
        url: app.globalData.interface+'//shangluo/API_4006_updateEmployeePassword ',
        method: 'POST',
        data: {
          EMPLOYEE_NAME: this.data.EMPLOYEE_NAME,
          EMPLOYEE_PASSWORD_OLD: this.data.EMPLOYEE_PASSWORD_OLD,
          EMPLOYEE_PASSWORD_NEW: this.data.EMPLOYEE_PASSWORD_NEW,
          EMPLOYEE_PASSWORD_REPEAT: this.data.EMPLOYEE_PASSWORD_REPEAT,
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res.data.result);
          if (res.data.result != 'success') {
            wx.showModal({
              title: '温馨提示',
              content: '原始密码和账户错误',
              success: function (res) {
                if (res.confirm) {//这里是点击了确定以后
                  console.log('用户点击确定')
                } else {//这里是点击了取消以后
                  console.log('用户点击取消')
                }
              }
            })
          }else{
            wx.showModal({
              title: '温馨提示',
              content: '修改成功',
              success: function (res) {
                if (res.confirm) {//这里是点击了确定以后
                  console.log('用户点击确定')
                } else {//这里是点击了取消以后
                  console.log('用户点击取消')
                }
              }
            })
          }
        }
      })
    }


  },








  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})